package thread3;

class Counter1 {
    public static int count = 0;

    public void increase() {
        count++;
    }
}

public class Test4 {
    public static void main(String[] args) throws InterruptedException {
        Counter1 counter = new Counter1();

        Thread t1 = new Thread(() -> {
            synchronized (counter) {
                for (int i = 0; i < 50000; i++) {
                    counter.increase();
                }
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized (counter) {
                for (int i = 0; i < 50000; i++) {
                    counter.increase();
                }
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println(Counter1.count);
    }
}
